import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class TestPresto {
    public static void testByPresto() throws Exception {
        Connection conn = DriverManager.getConnection("jdbc:presto://localhost:8080/hive/default", "root", null);
        Statement stm = conn.createStatement();
        ResultSet rs = stm.executeQuery("select a,cardinality(merge(cast(hll as hyperloglog))) from test_lh_hll2 group by a");
        while (rs.next()) {
            System.out.println(rs.getString(1) + ":" + rs.getInt(2));
        }
        rs.close();
        stm.close();
        conn.close();
    }

    public static void testByTrino() throws Exception {
        Properties properties = new Properties();
//        properties.setProperty("user", "root");
//        properties.setProperty("password", null);
//        properties.setProperty("SSL", "true");
        Connection conn = DriverManager.getConnection("jdbc:trino://localhost:8080/hive/default?user=root", properties);
        Statement stm = conn.createStatement();
        ResultSet rs = stm.executeQuery("select a,cardinality(merge(cast(hll as hyperloglog))) from test_lh_hll2 group by a");
        while (rs.next()) {
            System.out.println(rs.getString(1) + ":" + rs.getInt(2));
        }
        rs.close();
        stm.close();
        conn.close();
    }

    public static void main(String[] args) throws Exception {
//        testByPresto();
        testByTrino();
    }
}
